package mq;



import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.util.Scanner;

/**
 * @author Chenwx
 * @date 2021/5/13 14:15
 */
public class Producer {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        //创建生产者
        DefaultMQProducer p = new DefaultMQProducer("producer-group-1");
        //指定注册中心地址

        p.setNamesrvAddr("192.168.64.141:9876");

        //启动生产者

        p.start();
        //向Topic1发送消息
        //Topic1 相当于消息的一级分类
        //tag相当于二级分类
        while (true){
            System.out.println("输入消息：");
            String s=new Scanner(System.in).nextLine();
            //把字符互传封装到Message队列中
            Message msg = new Message("Topic1", "TagA", s.getBytes());
            msg.setDelayTimeLevel(3);
            SendResult r = p.send(msg);
            System.out.println(r);
        }
    }
}
